﻿Imports System.Data

Partial Class family_admin_addFamily
    Inherits System.Web.UI.Page

    Private _itemID As Integer
    Public Property itemID() As Integer
        Get
            Return _itemID
        End Get
        Set(ByVal value As Integer)
            _itemID = value
        End Set
    End Property

    Private _action As String
    Public Property action() As String
        Get
            Return _action
        End Get
        Set(ByVal value As String)
            _action = value
        End Set
    End Property


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        itemID = Request.QueryString("familyId")
        action = Request.QueryString("Action")

        If action = "Edit" Then
            frmFamily.DefaultMode = FormViewMode.Edit
        ElseIf action = "Add" Then
            frmFamily.DefaultMode = FormViewMode.Insert
        End If

        If Not Page.IsPostBack Then
            BindList()
        End If

    End Sub

    Protected Sub frmFamily_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles frmFamily.ItemInserted
        Response.Redirect("/default.aspx")
    End Sub


    Protected Sub frmFamily_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles frmFamily.ItemInserting
        Dim itemFrmView As FormView = CType(sender, FormView)
        Dim row As FormViewRow = itemFrmView.Row
        Dim txtFamilyName As TextBox = CType(row.FindControl("txtFamilyName"), TextBox)
        Dim txtMother As TextBox = CType(row.FindControl("txtMother"), TextBox)
        Dim txtFather As TextBox = CType(row.FindControl("txtPrice"), TextBox)
        Dim txtAddress As TextBox = CType(row.FindControl("txtAddress"), TextBox)
        Dim txtCity As TextBox = CType(row.FindControl("txtCity"), TextBox)
        Dim txtState As TextBox = CType(row.FindControl("txtState"), TextBox)
        Dim txtZip As TextBox = CType(row.FindControl("txtZip"), TextBox)
        Dim txtPhone1 As TextBox = CType(row.FindControl("txtPhone1"), TextBox)
        Dim txtPhone2 As TextBox = CType(row.FindControl("txtPhone2"), TextBox)
        Dim txtMemberCount As TextBox = CType(row.FindControl("txtMemberCount"), TextBox)


        Dim ddlParentFamily As DropDownList = CType(row.FindControl("ddlParentFamily"), DropDownList)
        e.Values.Add("PFamilyId", ddlParentFamily.SelectedValue)
        'e.Values.Add("FamilyName", txtFamilyName.Text)
        'e.Values.Add("Mother", txtMother.Text)
        'e.Values.Add("Father", txtFather.Text)
        'e.Values.Add("Address", txtAddress.Text)
        'e.Values.Add("City", txtCity.Text)
        'e.Values.Add("State", txtState.Text)
        'e.Values.Add("Zip", txtZip.Text)
        'e.Values.Add("Phone1", txtPhone1.Text)
        'e.Values.Add("Phone2", txtPhone2.Text)
        'e.Values.Add("MemberCount", txtMemberCount.Text)
    End Sub



    Sub BindList()
        Dim familyAdapter As New MainDbTableAdapters.FamiliesTableAdapter()
        Dim familyTable As New MainDb.FamiliesDataTable()
        familyTable = familyAdapter.GetFamilies()

        Dim row As FormViewRow = frmFamily.Row
        ' Populating the DropDownList Control inside the FormView control 
        Dim ddlParentFamily As DropDownList = DirectCast(row.FindControl("ddlParentFamily"), DropDownList)
        ddlParentFamily.DataSource = familyTable
        ddlParentFamily.DataValueField = familyTable.Columns("FamilyId").ColumnName
        ddlParentFamily.DataTextField = familyTable.Columns("FamilyName").ColumnName
        ddlParentFamily.DataBind()
    End Sub



    Protected Sub frmFamily_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmFamily.ModeChanged
        'If frmFamily.CurrentMode = FormViewMode.Edit Then
        '    BindList()
        'End If

    End Sub

End Class
